package dongshi.daddy.proxy.v2.cjlib;

import dongshi.daddy.proxy.v2.common.Transaction;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class ServiceMethodInterceptor implements MethodInterceptor {
    private Transaction transaction = new Transaction();
    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        // 开启事务（只需要写一次）
        transaction.beginTransaction();
        methodProxy.invokeSuper(o, objects);
        // 提交事务（只需要写一次）
        transaction.commit();
        return null;
    }
}
